package com.server.system.controller;

import com.server.common.code.utils.AjaxResult;
import com.server.common.code.utils.StringUtils;
import com.server.commons.sms.sms.JuHeSmsCommon;
import com.server.model.all.system.dto.SendSmsLoginDto;
import com.server.model.all.system.dto.SendSmsRegisterDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 发送短信
 * @author LXC
 * @date 2022/6/28 22:52
 */
@RestController
@RequestMapping(path = "/smsSend")
public class SmsSendController {

    @Resource
    private JuHeSmsCommon juHeSmsCommon;

    /**
     * 发送登录短信验证码
     * @author LXC
     * @date 2022/6/23 22:45
     */
    @PostMapping("/api/sendSmsLogin")
    public AjaxResult sendSmsLogin(@RequestBody @Validated SendSmsLoginDto smsLoginDto){
        juHeSmsCommon.sendLoginSms(smsLoginDto.getMobile(), StringUtils.createSmsCode());
        return AjaxResult.successMsg("发送成功");
    }

    /**
     * 发送注册短信验证码
     * @author LXC
     * @date 2022/6/23 22:45
     */
    @PostMapping("/api/sendSmsRegister")
    public AjaxResult sendSmsRegister(@RequestBody @Validated SendSmsRegisterDto sendSmsRegisterDto){
        juHeSmsCommon.sendRegisterSms(sendSmsRegisterDto.getMobile(), StringUtils.createSmsCode());
        return AjaxResult.successMsg("发送成功");
    }


    /**
     * 发送注册短信验证码
     * @author LXC
     * @date 2022/6/23 22:45
     */
    @PostMapping("/api/sendSmsForgetPassword")
    public AjaxResult sendSmsForgetPassword(@RequestBody @Validated SendSmsRegisterDto sendSmsRegisterDto){
        juHeSmsCommon.sendSmsForgetPassword(sendSmsRegisterDto.getMobile(), StringUtils.createSmsCode());
        return AjaxResult.successMsg("发送成功");
    }

}
